<?php

namespace Model;

class UserHandler{

	private $m_db = NULL;
	private $m_tablename = "login";
	
	public function __construct(Database $database) {
		$this->m_db = $database;
	}

	/**
	 * Hämtar ut alla användare ifrån databasen
	 */
	public function GetAllUsers()
	{
		$sql = 'SELECT * FROM login';
		$stmt = $this->m_db->Prepare($sql);
		
		$this->m_db->Execute($stmt);

		$userArray;

		$stmt->bind_result($userid, $username, $password, $superuser);

		while($stmt->fetch()){

			$user = new \Model\user($userid, $username, $password, $superuser);

			$userArray[] = $user;
		}
		
		return $userArray;
	}

	/**
	 * Tar bort en vald användare
	 * @param String $username användarnamnet på en användare som skall tas bort
	 */
	public function RemoveUser($userid){
		
		$sql = "DELETE FROM $this->m_tablename WHERE userid = ?";
		
		$stmt = $this->m_db->Prepare($sql);
		
		$stmt->bind_param("s", $userid);
		
		if($this->m_db->Execute($stmt)){
			$stmt->close();
			return true;
		}
		$stmt->close();
		return false;
	}
}
